package deepbitview

import grails.test.*
import grails.converters.JSON

class DeepViewAccessServiceTests extends GrailsUnitTestCase {

    String key

    protected void setUp() {
        super.setUp()

        //needs to be read from a configuration file
        key = ActiviationKeyHandler.getDeepBitActivationKey()
    }

    protected void tearDown() {
        super.tearDown()
    }

    /**
     * does the actual testing
     */
    void testReceiveData() {

        DeepViewAccessService deepViewAccessService = new DeepViewAccessService()
        TickerService tickerService = new TickerService()
        GlobalStatsService globalStatsService = new GlobalStatsService()

        deepViewAccessService.tickerService = tickerService
        deepViewAccessService.globalStatsService = globalStatsService

        deepViewAccessService.receiveData(key)

        assertTrue Worker.list().size() > 0
        assertTrue Sample.list().size() == 1
        assertTrue WorkerInstance.list().size() == Worker.list().size()
        deepViewAccessService.receiveData(key)

        assertTrue Worker.list().size() > 0
        assertTrue Sample.list().size() == 2
        assertTrue WorkerInstance.list().size()  == Worker.list().size()  * 2

        deepViewAccessService.receiveData(key)
        assertTrue Worker.list().size() > 0
        assertTrue Sample.list().size() == 3
        assertTrue WorkerInstance.list().size() == Worker.list().size() * 3
    }
}
